/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: liangyuanzhang
 * Date: 2025-3-07
 * Time: 18:26
 */
public class Example {

    public int countSegments(String s) {
        int count = 0;
        boolean inWorld = false;//是否处于单词中

        //遍历字符串每个字符
        for (int i = 0;i < s.length();i++){
            char c = s.charAt(i);

            if (c != ' '){//当字符串为非空格字符
                if(!inWorld){
                    count++;
                    inWorld = true;//+完之后更新状态:进入单词
                }
            }else{  //如果当前字符为空格字符
                inWorld = false;//更新状态:离开单词
            }
        }
        return count;
    }

    public static void main4(String[] args) {
        String s = "Hello";
        String ss = s.toLowerCase();
        System.out.println(ss);
    }

    public static void main3(String[] args) {
        String s1="abc"+"def";//1
        String s2=new String(s1);//2
        if(s1.equals(s2))//3
            System.out.println(".equals succeeded");//4
        if(s1==s2)//5
            System.out.println("==succeeded");//6
    }

    public static boolean isAdmin(String userId){
        return userId.toLowerCase()=="admin";
    }
    public static void main2(String[] args){
        System.out.println(isAdmin("Admin"));
    }

    String str = new String("good");
    char[ ] ch = { 'a' , 'b' , 'c' };
    public static void main1(String args[]){
        Example ex = new Example();
        ex.change(ex.str,ex.ch);
        System.out.print(ex.str + " and ");
        System.out.print(ex.ch);
    }
    public void change(String str,char ch[ ]){
        str = "test ok";
        ch[0] = 'g';
    }
}
